package com.gitee.sop.websiteserver.controller;

import com.alibaba.fastjson.JSONObject;
import com.gitee.sop.websiteserver.bean.Result;
import com.gitee.sop.websiteserver.entity.SenderConfig;
import com.gitee.sop.websiteserver.service.SendCodeHandler;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 消息配置接口
 *
 * @author admin
 */
@RestController
@RequestMapping("portal/messageConfig")
public class MessageConfigController {

    @Resource
    private SendCodeHandler sendCodeHandler;


    @PostMapping("/add")
    public Result config(@RequestBody @Valid SenderConfig senderConfig) {
        sendCodeHandler.addMessageConfig(senderConfig);
        return Result.ok();
    }

    @GetMapping("/get")
    public Result get(@RequestParam String appKey) {
        JSONObject jsonObject = sendCodeHandler.initConfig(appKey);
        String id = jsonObject.get("_id").toString();
        jsonObject.put("_id", id);
        return Result.ok(jsonObject);
    }

}
